package ie.ucc.cs.anggao.finalproject.client.ui.mainpanel.infopane.PageableFlextTable;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class flextable implements EntryPoint {

	private static Object[][] rowData = {
			{ "Richard", "Tattersall", "New York", "NY" },
			{ "Lynn", "Seckinger", "Valhalla", "NY" },
			{ "Gabriella", "Sarantini", "Yonkers", "NY" },
			{ "Homer", "Kenney", "Richmond", "VA" },
			{ "Anna", "Richards", "Buffalo", "NY" },
			{ "Gary", "VanMatre", "Castle Rock", "CO" },
			{ "Derek", "Roy", "Buffalo", "NY" },
			{ "Glenn", "Miller", "Atlanta", "GA" },
			{ "Brian", "Campbell", "Burlington", "VT" },
			{ "Claude", "Loublier", "Boston", "MA" },
			{ "Gilbert", "Perrault", "Las Vegas", "NV" },
			{ "Rene", "Robert", "Sacramento", "CA" },
			{ "Daniel", "Briere", "Rochester", "NY" }, };

	public void onModuleLoad() {
		final PageableFlexTable table = new PageableFlexTable(
				5) {
			public Object[][] getData(int index) {
				int pageSize = getPageSize();

				if (isLastPage(index))
					index = rowData.length - pageSize;

				Object[][] array = new Object[pageSize][];
				for (int row = index; row < index + pageSize; ++row) {
					array[row - index] = rowData[row];
				}
				return array;
			}

			public boolean isLastPage(int topOfPageIndex) {
				return topOfPageIndex + getPageSize() >= rowData.length;
			}
		};

		table.addColumn("First Name");
		table.addColumn("Last Name");
		table.addColumn("City");
		table.addColumn("State");

		RootPanel.get().add(table);
	}

}
